<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2019/4/24 0024
 * Time: 9:23
 */
namespace app\alipay;
require_once './AopSdk.php';
class Mzhifu{
    private $requeUrl = 'https://openapi.alipay.com/gateway.do';//配置请求接口
    private $appid = '2019031363527487';//配置支付宝appid
    private $private_key = 'MIIEpAIBAAKCAQEAwKwOJoHBN3Q4ISPlN5u40Nd97qC1NjffLdrmhYdYcmQIz4wKrZPy0ALElcxnHzepMnGsK2pWith60Uz50BWHkj6dFvaIa+EQO2hZdupaO3Kxb24+704f6pIay7/vXKmNqV7iO3pzpsIZYjIfLCh5oMay40XmNTeO8qu55pWZKpBoYGUHv71BjnjsrHJxcd9yKBUpuyEwW+CE66yord4S6vbaN9evTorO3AGGCMtJ5B7Xo6qh7FQRn/uHkxZH+LKQ30G/35yEy+xS64DsTcHUzMHyOcehiaWfXRNt9Ssrl3nLq2s82Xl7VbNiD+cFC3fs/r4eTr310pkQ8TivZpL6UwIDAQABAoIBAQCfPVSQpMshXu+JDFbE5/IOwRt23uIGRpUxG+tMTvldyamyh4bHwTB8lN0PBZnxJhqz81kdpMyUAqk3VQxe23xp9U/2C5nit2eoAe13J+ednIRjmVVwiTw9rbVx0lctWYEYi7AlAmaVW3SJQO2cnHMx2yc8SagjMaD2ldGWbuvhTXrvn1gVZIYwxtrKzXJJzHnJ2lhtp69fNAzhp3sJp/s5Hd9h4YSXMjNvbsDaaV7aKrsRo8/vwxsjS3uJOMTxY46u2TXljOSF12NgpemZRU3rN0XlL+7gClhbz14WAJ/SgUPFKf234DyW5KHgCXJrCBS5KaQgGAvtxg0Eix5QpZrpAoGBAOyHmxz7/T/tV2w1g7LlmrMlOcycY2eDUqNQ+/CJyvpdS2sZ0yab8aQ4Bj7qGj5SS8NzJ48cBVUK66HbvYtyqxXLfupFmGCUu/qkk2SH7FJmvac0zUlZLguCdaPT5cYFPleBPJ9Q0+Wcl7qGhf5U1MEpJmuK3eDf73NDSuTlJw5PAoGBANCIPLJVeR+QetrDHCZCu7Csu89FCIV6T1Bp6vyQGoCp8lhXppKqsTOYCYzFRNl5GTdN3OYYcK06t0jk7irDhBlIjekVpdBKvLvZvoaxv2m79Xm/BlbsPLlKTgnaWEniSmWjilgMYOGUXpR2fb7sZFdJaxNxXhSDkPbsXgvJS3a9AoGBAIydPXCoufC0N6HD2qyS5ToVKlxiqJHUN1+R+IUSVdIrfneIXcf5M1mOWOA0Ki/cmt/x6JWiceUR3e1WhkONgvotBSFfCGx6X5ptFpbQW4TNQXhS4qv1UXNUNn2TrmjfmyVIVnLcCWzagDVKXgRKCEVhIk8Suj9CwcaDPdYACQzvAoGAeV7R9PnKhZSR7MGioKI2m53tsbV8QDPv9d2v50/4HOrNIp3hVXwDpwPWixhF+k2BX67x4vpWmnySMNsNw9YIDK8t6XuwBot5TdxuB/dscR30wedsySq2LSISSanLuTT8GCwXWSfbO3AfnEla5sSvoh4ZNDfHiikJNq5cDoAabAECgYALSEskLcec1pKITCwVzloQIxK/IyxGEWsqVythaltcwhVkKUEXBkIXmxWQGjes0sKnZ0cc3C9q0jg1EsF0n+O4jqkOcqb/4brMgM6c5QOYkCRiPgm+lrrrUpL5JdZvbXCgNFwUcKchSrU+/0bZ3+ajIFQab91vJyJ10tFiGMnnTQ==';//配置支付宝密匙
    private $format = 'json';//设置返回格式
    private $charset = 'utf-8';//设置编码
    private $signType = 'RSA2';//设置签名方式
    private $public_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjEImHMnFwBjLcSF7SZv9NLHIlA2qDT6Zbdw8q4Rz56wxiKuYQXJVcBTdnUeX4zYo3fH8uzkdl0ZA5pMM1O+M9MqeuEF4QxAzBLt39xynLtazG9kV+/9lgoxPlwlYWZ0Zbc1swi253iyKtcwyPVlI17QwMI4anRUStB9JIk8jm7VfA1oSwEPttdMXOnDgfJTvcuXk/s1T+sqTP9twy3lBJTRXa/Sb13/LWd8aR51VIUuTeih6qZkGszrdPPZwBzuhBE5zBpO2g4Va72EAygZKwBKnPrFgYa3elRhBbd7VJxqNm72Y8oCA18ClO7Y5Am8t0KlbkCooGnD0zBy7q9FV0wIDAQAB';//设置支付宝公匙
    private $return_url = 'http://www.cdmxsmgs.com/index/index/myvip.html?bindex=4';//设置支付宝同步返回路径
    private $version = '1.0';//调用的接口版本
    private $notify_url = 'http://www.cdmxsmgs.com/api/api/zhifubao';//支付宝服务器主动通知商户服务器里指定的页面,异步回调地址
    private $out_trade_no = '';//定单号
    private $obj = '';//实例
    public function __construct($requeUrl=null,$appid=null,$private_key=null,
                                $format=null,$charset=null,$signType=null,$public_key=null)
    {
        if(isset($requeUrl)){
            $this->requeUrl = $requeUrl;
        }
        if(isset($appid)){
            $this->appid = $appid;
        }
        if(isset($private_key)){
            $this->private_key = $private_key;
        }
        if(isset($format)){
            $this->format = $format;
        }
        if(isset($charset)){
            $this->charset = $charset;
        }
        if(isset($signType)){
            $this->signType = $signType;
        }
        if(isset($public_key)){
            $this->public_key = $public_key;
        }
        $obj = new \AopClient();
        if(!$this->requeUrl){
            $this->requeUrl = config('alipay.requeUrl');
        }
        if(!$this->appid){
            $this->appid = config('alipay.appid');
        }
        if(!$this->private_key){
            $this->private_key = config('alipay.private_key');
        }
        if(!$this->format){
            $this->format = config('alipay.format');
        }
        if(!$this->format){
            $this->format = config('alipay.charset');
        }
        if(!$this->signType){
            $this->signType = config('alipay.signType');
        }
        if(!$this->public_key){
            $this->public_key = config('alipay.public_key');
        }
        if(!$this->return_url){
            $this->return_url = config('alipay.return_url');
        }
        if(!$this->version){
            $this->version = config('alipay.version');
        }
        if(!$this->notify_url){
            $this->notify_url = config('alipay.notify_url');
        }
        if($this->requeUrl&&$this->appid&&$this->private_key&&$this->format&&$this->charset&&$this->signType&&$this->public_key){
            $obj->gatewayUrl = $this->requeUrl;
            $obj->appId = $this->appid;
            $obj->rsaPrivateKey = $this->private_key;
            $obj->alipayPublicKey = $this->public_key;
            $obj->apiVersion = $this->version;
            $obj->signType = $this->signType;
            $obj->postCharset = $this->charset;
            $obj->format = $this->format;
            $this->obj = $obj;
        }else{
            return false;
        }
    }
    /**
     * @param 订单金额 $number
     * @param 商品的标题 $subject
     * @param string商户网站唯一订单号 $out_trade_no
     * @param null描述信息 $body
     * @param null同步回跳地址 $return_url
     * @param null绝对超时时间 $time_expire
     * @param array $goods_detail
     * @param null公用回传参数 $passback_params
     * @param null业务扩展参数 $extend_params
     * @param null商品主类型：0—虚拟类商品，1—实物类商品注：虚拟类商品不支持使用花呗渠道 $goods_type
     * @param null该笔订单允许的最晚付款时间 $timeout_express
     * @param string $user_id
     * @return string|\提交表单HTML文本
     * @throws \Exception
     */
    public function getQu($number,$subject,$out_trade_no='',$body=null,$return_url=null,$time_expire=null,$goods_detail=[],$passback_params=null,
                          $extend_params=null,$goods_type=null,$timeout_express=null,$user_id=''){
        if($return_url){
            $this->requeUrl = $return_url;
        }
        $requery = new \AlipayTradePagePayRequest();
        $requery->setReturnUrl($this->return_url);
        $requery->setNotifyUrl($this->notify_url);
        $this->out_trade_no = $out_trade_no;
        $text['out_trade_no'] = $this->out_trade_no;
        $text['product_code'] = 'FAST_INSTANT_TRADE_PAY';
        $text['total_amount'] =$number;
        $text['subject'] =$subject;
        if($body){
            $text['body'] =$body;
        }
        if($time_expire){
            $text['time_expire'] =$time_expire;
        }
        if($goods_detail){
            $text['goods_detail'] =$goods_detail;
        }
        if($passback_params){
            $text['passback_params'] =urlencode($passback_params);
        }
        if($extend_params){
            $text['extend_params'] =$extend_params;
        }
        if($goods_type){
            $text['goods_type'] =$goods_type;
        }
        if($timeout_express){
            $text['timeout_express'] =$timeout_express;
        }
        $text = json_encode($text);
        $requery->setBizContent($text);
//        return $this->obj;
        $form = $this->obj->pageExecute($requery);
        return $form;
    }
    public function getOut_trade_no(){
        return $this->out_trade_no;
    }
}